#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdbool.h>


struct TreeNode {
    int val;
    struct TreeNode* left;
    struct TreeNode* right;
};

bool IsTreeSame(struct TreeNode* p, struct TreeNode* q)
{
    if (!p && !q)
        return true;
    if ((!p && q) || (!q && p))
        return false;
    if (p->val != q->val)
        return false;
    return IsTreeSame(p->left, q->left) && IsTreeSame(p->right, q->right);
}

bool isSubtree(struct TreeNode* root, struct TreeNode* subRoot) {
    if (subRoot == NULL)
        return true;
    if (IsTreeSame(root, subRoot))
        return true;
    if (!root->left && !root->right)
        return false;
    if (root->left && !root->right)
        return IsTreeSame(root->left, subRoot) || isSubtree(root->left, subRoot);
    if (root->right && !root->left)
        return IsTreeSame(root->right, subRoot) || isSubtree(root->right, subRoot);
    return isSubtree(root->left, subRoot) || isSubtree(root->right, subRoot);
}